def is_prime(n):
    if n < 2:
        return False
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True
def next_prime(n):
    while True:
        if is_prime(n):
            return n
        n += 1
def word_to_number(word):
    numbers = {"zero": 0, "one": 1, "two": 2, "three": 3, "four": 4, "five": 5, "six": 6, "seven": 7, "eight": 8, "nine": 9}
    return numbers.get(word)
words = input().split()
if len(words) != 3:
    print("wrong input")
else:
    num = 100 * word_to_number(words[0]) + 10 * word_to_number(words[1]) + word_to_number(words[2])
    if num < 100 or num > 999:
        print("wrong input")
    else:
        result = next_prime(num)
        print(result)  
